<?php

require_once BASE_PATH . 'application/models/basedao' . EXT;

class sessionDAO extends baseDAO {

    var $table = 'ci_sessions';
    var $key = 'session_id';
    var $sql = '';

    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }

    function setUserId($user_k) {
        $this->_update(array("user_id" => $user_k), array($this->key => $this->getId()));
    }

    function getSession() {
        return $this->session->all_userdata();
    }

    function setSession($data = array()) {
        $this->session->set_userdata($data);
    }

    function getId() {
        return $this->session->userdata("session_id");
    }

    function isLogin() {
        $login = 0;

        $usuario_k = $this->getUserId();

        if ($usuario_k != 0)
            $login = 1;

        return $login;
    }

    function getUserId() {

        $result = 0;
        $query = $this->findById($this->getId());


        if (!empty($query))
            $result = $query->user_id;

        return $result;
    }

    function logOut() {
        $this->delete($this->getId());
        $this->session->sess_destroy();
    }

    public function getUser() {
        $user = false;
        $this->load->model('suscriptoresDAO');

        if ($this->isLogin()) {
            $user_id = $this->getUserId();
            $user = $this->suscriptoresDAO->_findById($user_id);
        }

        return $user;
    }

}

?>